// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.MachineLearning;

public sealed partial class DataframeAnalysisFeatureProcessorNGramEncoding
{
	[JsonInclude, JsonPropertyName("custom")]
	public bool? Custom { get; set; }

	/// <summary>
	/// <para>
	/// The feature name prefix. Defaults to ngram_&lt;start>_&lt;length>.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("feature_prefix")]
	public string? FeaturePrefix { get; set; }

	/// <summary>
	/// <para>
	/// The name of the text field to encode.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("field")]
	public Elastic.Clients.Elasticsearch.Field Field { get; set; }

	/// <summary>
	/// <para>
	/// Specifies the length of the n-gram substring. Defaults to 50. Must be greater than 0.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("length")]
	public int? Length { get; set; }

	/// <summary>
	/// <para>
	/// Specifies which n-grams to gather. It’s an array of integer values where the minimum value is 1, and a maximum value is 5.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("n_grams")]
	public ICollection<int> NGrams { get; set; }

	/// <summary>
	/// <para>
	/// Specifies the zero-indexed start of the n-gram substring. Negative values are allowed for encoding n-grams of string suffixes. Defaults to 0.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("start")]
	public int? Start { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisFeatureProcessor(DataframeAnalysisFeatureProcessorNGramEncoding dataframeAnalysisFeatureProcessorNGramEncoding) => Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisFeatureProcessor.NGramEncoding(dataframeAnalysisFeatureProcessorNGramEncoding);
}

public sealed partial class DataframeAnalysisFeatureProcessorNGramEncodingDescriptor<TDocument> : SerializableDescriptor<DataframeAnalysisFeatureProcessorNGramEncodingDescriptor<TDocument>>
{
	internal DataframeAnalysisFeatureProcessorNGramEncodingDescriptor(Action<DataframeAnalysisFeatureProcessorNGramEncodingDescriptor<TDocument>> configure) => configure.Invoke(this);

	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor() : base()
	{
	}

	private bool? CustomValue { get; set; }
	private string? FeaturePrefixValue { get; set; }
	private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; }
	private int? LengthValue { get; set; }
	private ICollection<int> NGramsValue { get; set; }
	private int? StartValue { get; set; }

	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor<TDocument> Custom(bool? custom = true)
	{
		CustomValue = custom;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The feature name prefix. Defaults to ngram_&lt;start>_&lt;length>.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor<TDocument> FeaturePrefix(string? featurePrefix)
	{
		FeaturePrefixValue = featurePrefix;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The name of the text field to encode.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor<TDocument> Field(Elastic.Clients.Elasticsearch.Field field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The name of the text field to encode.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor<TDocument> Field<TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The name of the text field to encode.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor<TDocument> Field(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Specifies the length of the n-gram substring. Defaults to 50. Must be greater than 0.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor<TDocument> Length(int? length)
	{
		LengthValue = length;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Specifies which n-grams to gather. It’s an array of integer values where the minimum value is 1, and a maximum value is 5.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor<TDocument> NGrams(ICollection<int> nGrams)
	{
		NGramsValue = nGrams;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Specifies the zero-indexed start of the n-gram substring. Negative values are allowed for encoding n-grams of string suffixes. Defaults to 0.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor<TDocument> Start(int? start)
	{
		StartValue = start;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (CustomValue.HasValue)
		{
			writer.WritePropertyName("custom");
			writer.WriteBooleanValue(CustomValue.Value);
		}

		if (!string.IsNullOrEmpty(FeaturePrefixValue))
		{
			writer.WritePropertyName("feature_prefix");
			writer.WriteStringValue(FeaturePrefixValue);
		}

		writer.WritePropertyName("field");
		JsonSerializer.Serialize(writer, FieldValue, options);
		if (LengthValue.HasValue)
		{
			writer.WritePropertyName("length");
			writer.WriteNumberValue(LengthValue.Value);
		}

		writer.WritePropertyName("n_grams");
		JsonSerializer.Serialize(writer, NGramsValue, options);
		if (StartValue.HasValue)
		{
			writer.WritePropertyName("start");
			writer.WriteNumberValue(StartValue.Value);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class DataframeAnalysisFeatureProcessorNGramEncodingDescriptor : SerializableDescriptor<DataframeAnalysisFeatureProcessorNGramEncodingDescriptor>
{
	internal DataframeAnalysisFeatureProcessorNGramEncodingDescriptor(Action<DataframeAnalysisFeatureProcessorNGramEncodingDescriptor> configure) => configure.Invoke(this);

	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor() : base()
	{
	}

	private bool? CustomValue { get; set; }
	private string? FeaturePrefixValue { get; set; }
	private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; }
	private int? LengthValue { get; set; }
	private ICollection<int> NGramsValue { get; set; }
	private int? StartValue { get; set; }

	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor Custom(bool? custom = true)
	{
		CustomValue = custom;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The feature name prefix. Defaults to ngram_&lt;start>_&lt;length>.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor FeaturePrefix(string? featurePrefix)
	{
		FeaturePrefixValue = featurePrefix;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The name of the text field to encode.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor Field(Elastic.Clients.Elasticsearch.Field field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The name of the text field to encode.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor Field<TDocument, TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The name of the text field to encode.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor Field<TDocument>(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Specifies the length of the n-gram substring. Defaults to 50. Must be greater than 0.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor Length(int? length)
	{
		LengthValue = length;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Specifies which n-grams to gather. It’s an array of integer values where the minimum value is 1, and a maximum value is 5.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor NGrams(ICollection<int> nGrams)
	{
		NGramsValue = nGrams;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Specifies the zero-indexed start of the n-gram substring. Negative values are allowed for encoding n-grams of string suffixes. Defaults to 0.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorNGramEncodingDescriptor Start(int? start)
	{
		StartValue = start;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (CustomValue.HasValue)
		{
			writer.WritePropertyName("custom");
			writer.WriteBooleanValue(CustomValue.Value);
		}

		if (!string.IsNullOrEmpty(FeaturePrefixValue))
		{
			writer.WritePropertyName("feature_prefix");
			writer.WriteStringValue(FeaturePrefixValue);
		}

		writer.WritePropertyName("field");
		JsonSerializer.Serialize(writer, FieldValue, options);
		if (LengthValue.HasValue)
		{
			writer.WritePropertyName("length");
			writer.WriteNumberValue(LengthValue.Value);
		}

		writer.WritePropertyName("n_grams");
		JsonSerializer.Serialize(writer, NGramsValue, options);
		if (StartValue.HasValue)
		{
			writer.WritePropertyName("start");
			writer.WriteNumberValue(StartValue.Value);
		}

		writer.WriteEndObject();
	}
}